<?php

/**
 * @Author: wuchenge
 * @Date:   2021-12-14 16:49:05
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Http\Middleware;

use App\Http\Controllers\ApiController;
use App\Libraries\JwtToken;
use App\Models\Admin\Admin as AdminModel;
use Closure;

class Admin extends ApiController
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        // 拿到用户
        $admin = JwtToken::authToken(AdminModel::class);
        if (!$admin) {
            return $this->setErrorCode(100401, '请登录')->response();
        }

        $mid_params = ['admin' => $admin];
        $request->attributes->add($mid_params); //添加参数
        return $next($request);
    }
}
